package com.liuh.appsys.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.liuh.appsys.dao.AppInfoMapper;
import com.liuh.appsys.pojo.AppInfo;
import com.liuh.appsys.tools.PageSupport;

/**
 * @note appInfo 
 * @author liuh
 * */
@Service
public class AppInfoServiceImpl implements AppInfoService{

	@Resource
	AppInfoMapper appInfoMapper;
	
	@Override
	public List<AppInfo> getAppInfo(AppInfo appInfo,int currentPageNo,int pageSize) {
		// TODO Auto-generated method stub
		return appInfoMapper.findAppInfoList(appInfo,currentPageNo,pageSize);
	}
	
	/**
	 * @note 根据组合条件 分页查询
	 * @author liuh
	 * */
	@Override
	public PageSupport getAppInfos(AppInfo appInfo,int currentPageNo,int pageSize) {
		//组合条件查询到的数据
		List<AppInfo> data=appInfoMapper.findAppInfoList(appInfo,(currentPageNo-1)*pageSize,pageSize);
		//组合条件查询到的数据量
		int count=appInfoMapper.getAppInfoCount(appInfo);
		//分页工具类
		PageSupport page=new PageSupport();
		page.setData(data);
		page.setPageSize(pageSize);
		page.setTotalCount(count);
		page.setCurrentPageNo(currentPageNo);
		return page;
	}

	@Override
	public boolean add(AppInfo appInfo) {
		// TODO Auto-generated method stub
		int result= appInfoMapper.insertAppInfo(appInfo);
		if(result>0) {
			return true;
		}
		return false;
	}

	@Override
	public String isExistApkName(String apkName) {
		String result="noexist";
		AppInfo appInfo=new AppInfo();
		appInfo.setAPKName(apkName);
		//组合条件查询到的数据
		List<AppInfo> data=appInfoMapper.findAppInfoList(appInfo,0,1);
		if(data.size()>0) {
			result="exist";
		}
		return result;
	}

}
